<?php
/**
 * 合作商信息
**/
include("../includes/common.php");
$title='合作商信息';
include './head.php';
if($islogin==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
?>
  <div class="container" style="padding-top:70px;">
<?php

$my=isset($_GET['my'])?$_GET['my']:null;

if($my=='add')
{
?>
<div class="col-sm-12 col-md-10 col-lg-8 center-block" style="float: none;">
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title">添加合作商</h3></div>
<div class="panel-body">
<form method="POST" onsubmit="return addUser(this)">
<div class="form-group">
<label>手机号(登录账号):</label><br>
<input type="text" class="form-control" name="tel" value="" placeholder="可留空">
</div>
<div class="form-group">
<label>邮箱(登录账号):</label><br>
<input type="text" class="form-control" name="email" value="" placeholder="可留空">
</div>
<div class="form-group">
<label>登录密码:</label><br>
<input type="text" class="form-control" name="password" value="" placeholder="留空则只能使用密钥登录">
</div>
<div class="form-group">
<label>合作商名称:</label><br>
<input type="text" class="form-control" name="name" value="" placeholder="请输入合作商名称">
</div>
<div class="form-group">
<label>ＱＱ:</label><br>
<input type="text" class="form-control" name="qq" value="" placeholder="可留空">
</div>
<div class="form-group">
<label>网站域名:</label><br>
<input type="text" class="form-control" name="domain" value="" placeholder="可留空">
</div>
<div class="form-group">
    <label>商户状态:</label><br><select class="form-control" name="status"><option value="1">1_正常</option><option value="0">0_封禁</option></select>
</div>
<input type="submit" class="btn btn-primary btn-block" value="确定添加"></form>
<br/><a href="./partner.php">>>返回合作商列表</a>
</div></div>
<?php }
elseif($my=='edit')
{
$id=intval($_GET['id']);
$row=$DB->getRow("select * from pre_partner where id='$id' limit 1");
if(!$row)showmsg('该合作商不存在',4);
?>
<div class="col-md-12 col-lg-10 center-block" style="float: none;">
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title">修改合作商信息 ID:<?php echo $id?></h3></div>
<div class="panel-body">
<form onsubmit="return editUser(this, <?php echo $id?>)" method="POST">
<div class="row">
<div class="col-sm-12 col-md-12">
<div class="form-group">
<label>手机号(登录账号):</label><br>
<input type="text" class="form-control" name="tel" value="<?php echo $row['tel']?>" placeholder="可留空">
</div>
<div class="form-group">
<label>邮箱(登录账号):</label><br>
<input type="text" class="form-control" name="email" value="<?php echo $row['email']?>" placeholder="可留空">
</div>
<div class="form-group">
<label>合作商名称:</label><br>
<input type="text" class="form-control" name="name" value="<?php echo $row['name']?>" placeholder="请输入合作商名称">
</div>
<div class="form-group">
<label>ＱＱ:</label><br>
<input type="text" class="form-control" name="qq" value="<?php echo $row['qq']?>" placeholder="可留空">
</div>
<div class="form-group">
<label>网站域名:</label><br>
<input type="text" class="form-control" name="domain" value="<?php echo $row['domain']?>" placeholder="可留空">
</div>
<div class="form-group">
    <label>商户状态:</label><br><select class="form-control" name="status" default="<?php echo $row['status']?>"><option value="1">1_正常</option><option value="0">0_封禁</option></select>
</div>
<h4><font color="blue">密码修改</font></h4>
<div class="form-group">
<label>重置登录密码:</label><br>
<input type="text" class="form-control" name="password" value="" placeholder="不重置密码请留空">
</div>
</div>
</div>
<input type="submit" class="btn btn-primary btn-block" value="确定修改"></form>
<br/><a href="./partner.php">>>返回合作商列表</a>
</div></div>
<script>
var items = $("select[default]");
for (i = 0; i < items.length; i++) {
	$(items[i]).val($(items[i]).attr("default")||0);
}
</script>

<?php } ?>
    </div>
  </div>
<script src="<?php echo $cdnpublic?>layer/3.1.1/layer.js"></script>
<script>
function addUser(obj){
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'POST',
		url : 'ajax_partner.php?act=addUser',
		data : $(obj).serialize(),
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				layer.alert('添加合作商成功！合作商ID：'+data.id+'<br/>密钥：'+data.sign_key, {
					icon: 1,
					closeBtn: false
				}, function(){
					window.location.href = './partner.php';
				});
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.close(ii);
			layer.msg('服务器错误');
		}
	});
	return false;
}
function editUser(obj, id){
	var ii = layer.load(2, {shade:[0.1,'#fff']});
	$.ajax({
		type : 'POST',
		url : 'ajax_partner.php?act=editUser&id='+id,
		data : $(obj).serialize(),
		dataType : 'json',
		success : function(data) {
			layer.close(ii);
			if(data.code == 0){
				layer.alert('修改合作商信息成功！', {
					icon: 1,
					closeBtn: false
				});
			}else{
				layer.alert(data.msg, {icon: 2})
			}
		},
		error:function(data){
			layer.close(ii);
			layer.msg('服务器错误');
		}
	});
	return false;
}
</script>